const mongoose = require('mongoose');
const { ObjectId } = mongoose.Schema;

/**
 * Export model definition object.
 */
const userDefinedFieldSchema = mongoose.Schema({
  key: {
    type: ObjectId,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  value: {
    type: String,
    default: '',
  },
}, { _id: false });

module.exports = {
  functionId: {
    type: ObjectId,
    index: true,
  },
  projectId: ObjectId,
  versionId: {
    type: ObjectId,
    index: true,
  },
  fileId: {
    type: ObjectId,
    index: true,
  },
  status: { type: Number, default: 0 },
  kind: Number,
  resultKind: { type: Number, default: 0 },
  description: String,
  requirementInfo: String,
  identifierNumber: Number,
  data: Object,
  decisions: Array,
  taskId: String,
  log: Object,
  number: Number,
  location: Object,
  statementCovered: { type: Number, default: 0 },
  branchCovered: { type: Number, default: 0 },
  mcdcCovered: { type: Number, default: 0 },
  conditionCovered: { type: Number, default: 0 },
  decisionCovered: { type: Number, default: 0 },
  invokedFuncCovered: { type: Number, default: 0 },
  invokeCovered: { type: Number, default: 0 },
  userDefinedFields: [userDefinedFieldSchema],
  execCount: {
    type: Number,
    default: 1,
  },
  originalImportedId: ObjectId,
  // 回归版本测试用例来源：0--用例复用，1--用例新增
  sourceInRegression: { type: Number, default: 1 },
  // 用例分组
  typeName: {
    type: String,
    enum: [
      'GN', // 功能
      'JK', // 借口
      'BJ', // 边界
      'LJ', // 逻辑
      'XN', // 性能
    ],
  },
  // 某个函数内的某个分组内的编号, 从1开始
  typeNumber: Number,
  // ${type}_${functionName}_${typeNumber}
  typeNumberString: String,
  testMethod: Array,
  // 记录测试用例是否更新的版本hash
  hash: String,
};
